package com.lc.luzhengtang.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.conn.Conn;

import java.util.List;


/**
 * Created by Administrator on 2017/7/1.
 */

public class MyGridAdapter2 extends BaseAdapter {
    private Context mContext;
    private List<String> data;
/*
    public String[] img_text = { "健康知识", "健康知识", "健康知识", "健康知识", "健康知识", "健康知识",
            "健康知识", "健康知识", "问卷调查", };
    public int[] imgs = { R.mipmap.healthy, R.mipmap.healthy,
            R.mipmap.healthy, R.mipmap.healthy,
            R.mipmap.healthy, R.mipmap.healthy,
            R.mipmap.healthy, R.mipmap.healthy, R.mipmap.answer };*/

    public MyGridAdapter2(Context mContext, List<String> data) {
        super();
        this.mContext = mContext;
        this.data = data;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final MyGridAdapter2.ViewHolder holder;

        if (convertView == null) {

            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_pic, parent, false);


            holder = new MyGridAdapter2.ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (MyGridAdapter2.ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(Conn.HOST3 +data.get(position)).crossFade().into(holder.iv_chose);
        holder.text_heheda.setText(data.get(position));
        return convertView;
    }

    //初始化控件
    class ViewHolder {
        ImageView iv_chose;

TextView text_heheda;

        public ViewHolder(View itemView) {
            iv_chose = (ImageView) itemView.findViewById(R.id.img_glide);
            text_heheda= (TextView) itemView.findViewById(R.id.text_heheda);
        }

    }
}
